package com.lmk.qs.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * DDL操作
 */
public class test03 {
   public static void main(String[] args) {
        Statement st=null;
        Connection connection=null;
        //insert语句需求
        try {
            Class.forName("com.mysql.jdbc.Driver");
            try {
                connection= DriverManager.getConnection("jdbc:mysql://localhost:3306/ll","root","root");
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
            String str="create table student(id int, name varchar(20))";
            try {
                st=connection.createStatement();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
            int i= 0;
            try {
                i = st.executeUpdate(str);
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }

            System.out.println(i);
            if(i>0){
                System.out.println("打印成功");
            }else System.out.println("打印失败");

        } catch (  ClassNotFoundException e) {
            e.printStackTrace();
        }finally {
            //避免空指针异常
            if(st!=null){
                try {
                    st.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }
            if(connection!=null){
                try {
                    st.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }

        }

    }
}
